import { createPinia } from 'pinia'
import { createPersistedState } from 'pinia-plugin-persistedstate'
import Env from '@/env'

const pinia = createPinia()

pinia.use(
	createPersistedState({
		storage: {
			getItem(key: string) {
				return uni.getStorageSync(key)
			},
			setItem(key: string, value: any) {
				uni.setStorageSync(key, value)
			}
		},
		auto: true,
		key: (id) => Env.cachePrefix + id
	})
)

export default pinia
